import type { XLabelType, YLabelType } from '@/index.d';
import { dayjs } from 'element-plus';
import markdownit from 'markdown-it';
import hljs from 'highlight.js';

export const aiModelList: Array<string> = [
  'qwen-max',
  'deepseek-r1',
  'deepseek-v3.1',
  'qwen3-max-preview',
  'Moonshot-Kimi-K2-Instruct'
];

export const baseUrl = computed(() => (import.meta.env.MODE === 'development' ? '/apDev' : '/api'));

export const mdTool = markdownit({
  highlight: (str: string, lang: string, attrs: string) => {
    if (lang && hljs.getLanguage(lang)) {
      try {
        return hljs.highlight(lang, str).value;
      } catch (__) {}
    }
    return ''; // 使用额外的默认转义
  },
  html: true,
  linkify: true,
  typographer: true
});

export const getUniqueKeysFromObjectArray = (arr: any[], key: string): Array<string> => {
  return arr.map(item => item[key]).filter((value, index, self) => self.indexOf(value) === index);
};

export const getArraySum = (arr: any[], key: string): number => {
  return arr.reduce((acc, cur) => acc + cur[key], 0);
};

export const generateSimpleId = () => {
  // 时间戳（毫秒）+ 3位随机数，确保同一毫秒内不重复
  return Date.now().toString(36) + Math.random().toString(36).slice(2, 3);
};
export const personList = [
  '汤一炯',
  '周海波',
  '韩嘉懿',
  '瞿军华',
  '沈杰',
  '桂华',
  '吴忠华',
  '郭家雷',
  '张健',
  '蔡锦江',
  '陈智耀',
  '周春华',
  '吴刚',
  '许春军',
  '卲灵',
  '罗凯',
  '罗来藤',
  '相海清',
  '卫宇峰',
  '朱顺',
  '周建',
  '杨宏阔',
  '陈斌晟',
  '韩江锐',
  '吴昊锋'
];

export const defectTypeList = {
  RT: ['夹渣', '气孔', '夹钨', '未熔合', '未焊透', '裂纹', '密集气孔'],
  UT: ['面积型', '体积型'],
  PT: ['圆形', '线性'],
  MT: ['圆形', '线性']
};

export const makeMethodList = ['SAW', 'SMAW', 'ESW', 'GTAW', '机加工', '其它'];

export const partTypeList = ['低合金钢焊缝', '堆焊层', '异种金属焊缝', '机加工件', '其它'];

export const testStageList = ['焊后', '热处理后', '水压试验后', '机加工后', '其它'];

export const ownerList = ['中核', '广核', '国核', '其它'];

export const provinceList = [
  '北京市',
  '天津市',
  '河北省',
  '山西省',
  '内蒙古自治区',
  '辽宁省',
  '吉林省',
  '黑龙江省',
  '上海市',
  '江苏省',
  '浙江省',
  '安徽省',
  '福建省',
  '江西省',
  '山东省',
  '河南省',
  '湖北省',
  '湖南省',
  '广东省',
  '广西壮族自治区',
  '海南省',
  '四川省',
  '贵州省',
  '云南省',
  '西藏自治区',
  '陕西省',
  '甘肃省',
  '青海省',
  '宁夏回族自治区',
  '新疆维吾尔自治区'
];

export const getDefectListData = (xLabel: XLabelType, yLabel: YLabelType, top: number = 4) => {};

export const getYearMonthStr = (length: number = 6): Array<string> => {
  const months: Array<string> = [];
  let year = dayjs().year();
  let month = dayjs().month();
  for (let index = 0; index < length; index++) {
    let monthStr: string = month < 10 ? `0${month}` : month + '';
    months.push(`${year}-${monthStr}`);
    if (month === 1) {
      month = 12;
      year--;
    } else {
      month--;
    }
  }
  return months;
};
